//
//  OrderDetailViewModel.m
//  didacar
//
//  Created by 度周末网络-王腾 on 16/1/12.
//  Copyright © 2016年 dzmmac. All rights reserved.
//

#import "OrderDetailViewModel.h"
#import "NSDate+WQCalendarLogic.h"
#import "ResponseDayModel.h"
#import "KDateFormatter.h"

@implementation OrderDetailViewModel

-(id)init{
    self.dayRefundTickets = [[NSMutableArray alloc ] init];
    return [super init];
}

/**
 *  获取直通车订单详情
 *
 *  @param resultBlock
 */
-(void)getOrderDetailThroughBusData:(DealDataResultBlock)resultBlock{
    NSMutableDictionary *postData = [[NSMutableDictionary alloc ] init];
    [postData setObj:@(self.TicketOrderId) forKey:@"TicketOrderId"];
      [postData setObj:USERINFOManager.getUserInfo.MemberId forKey:@"MemberId"];
    WEAKSELF
    [[BaseHttpRequest sharedInstance]  sendRequestToPost:ThroughBusOrderDetail withData:postData alertMessage:@"" success:^(NSDictionary *dicData) {
        
        weakSelf.orderDetailRegularBusModel = [[OrderDetailRegularBusModel alloc ] initWithDictionary:dicData];
        
        resultBlock(1,nil,nil);
    } error:^(NSString *errorMsg) {
        resultBlock(0,nil,errorMsg);
    }];
}

/**
 *  获取班车订单详情
 *
 *  @param resultBlock
 */
-(void)getOrderDetailRegularBusData:(DealDataResultBlock)resultBlock{
    
    NSMutableDictionary *postData = [[NSMutableDictionary alloc ] init];
    [postData setObj:@(self.TicketOrderId) forKey:@"TicketOrderId"];
    [postData setObj:USERINFOManager.getUserInfo.MemberId forKey:@"MemberId"];
    
    WEAKSELF
    [[BaseHttpRequest sharedInstance]  sendRequestToPost:WorkOrderDetail withData:postData alertMessage:nil success:^(NSDictionary *dicData) {
        
        weakSelf.orderDetailRegularBusModel = [[OrderDetailRegularBusModel alloc ] initWithDictionary:dicData];
    
        resultBlock(1,nil,nil);
    } error:^(NSString *errorMsg) {
        resultBlock(0,nil,errorMsg);
    }];
}

/**
 *  退款
 *
 *  @param resultBlock
 */
-(void)refundTicket:(DealDataResultBlock)resultBlock{
    NSMutableDictionary *postData = [[NSMutableDictionary alloc ] init];
    [postData setObj:@(self.TicketOrderId) forKey:@"TicketOrderId"];
    [postData setObj:USERINFOManager.getUserInfo.MemberId forKey:@"MemberId"];
    
    NSMutableArray *post = [[NSMutableArray alloc ] init];
    for (CalendarDayModel *model in self.dayRefundTickets) {
       
        [post addObject:@(model.DetailId).stringValue];
    }
    
    [postData setObj:post forKey:@"TicketOrderDetailId"];
    
    [[BaseHttpRequest sharedInstance]  sendRequestToPost:RefundTicket withData:postData alertMessage:@"" success:^(NSDictionary *dicData) {
        
        resultBlock(1,nil,nil);
    } error:^(NSString *errorMsg) {
        resultBlock(0,nil,errorMsg);
    }];

}


/**
 *  取消订单
 *
 *  @param resultBlock
 */
-(void)cancelOrder:(DealDataResultBlock)resultBlock{
    NSMutableDictionary *postData = [[NSMutableDictionary alloc ] init];
    [postData setObj:@(self.TicketOrderId) forKey:@"TicketOrderId"];
    [postData setObj:USERINFOManager.getUserInfo.MemberId forKey:@"MemberId"];
  
    [[BaseHttpRequest sharedInstance]  sendRequestToPost:@"TicketOrder.CanelTicketOrder" withData:postData alertMessage:@"" success:^(NSDictionary *dicData) {
        
        resultBlock(1,nil,nil);
    } error:^(NSString *errorMsg) {
        resultBlock(0,nil,errorMsg);
    }];
}
/**
 *  获取直通车线路日期
 *
 *  @return
 */
-(NSMutableArray *)getThroughBusLineDateList{
    NSMutableArray *array = [NSMutableArray array];
    for (TicketOrderWorkDetailEntiy *entity in self.orderDetailRegularBusModel.orderDetailList) {
         ResponseDayModel *model = [[ResponseDayModel alloc] init];
         model.time  = entity.DetailDate;
         model.price = entity.Price.stringValue;

         model.ticketStyle = entity.Type;
         model.DetailId = entity.DetailId;
        [array addObject:model];
    }
   
    return array;
    
}

@end
